- add_page_specific_style 'page_bundles/branches'
- title = _('Branches')
- page_title title
- search = params[:search]

-# Possible values for variables passed down from the projects/branches_controller.rb
-#
-#   @mode   - overview|active|stale|all (default:overview)
-#   @sort   - name_asc|updated_asc|updated_desc

%h1.gl-sr-only= title

.gl-flex.gl-border-b-1.gl-border-b-solid.gl-border-b-default.gl-flex-wrap-reverse
  = gl_tabs_nav({ class: 'gl-grow gl-border-b-0' }) do
    = gl_tab_link_to s_('Branches|Overview'), project_branches_path(@project), { item_active: @mode == 'overview', title: s_('Branches|Show overview of the branches') }
    = gl_tab_link_to s_('Branches|Active'), project_branches_filtered_path(@project, state: 'active'), { item_active: @mode == 'active', title: s_('Branches|Show active branches') }
    = gl_tab_link_to s_('Branches|Stale'), project_branches_filtered_path(@project, state: 'stale'), { item_active: @mode == 'stale', title: s_('Branches|Show stale branches') }
    = gl_tab_link_to s_('Branches|All'), project_branches_filtered_path(@project, state: 'all'), { item_active: %w[overview active stale].exclude?(@mode), title: s_('Branches|Show all branches') }

  .gl-flex.gl-items-center.gl-gap-3.gl-mt-3.gl-ml-auto{ class: '@sm/panel:gl-mt-0' }
    - if can_view_branch_rules?
      = render Pajamas::ButtonComponent.new(variant: :confirm, category: :tertiary, href: project_settings_repository_path(@project, anchor: 'js-branch-rules'), button_options: { data: { testid: "view-branch-rules" }}) do
        = s_('Branches|View branch rules')

    - if can_push_code?
      = link_button_to new_project_branch_path(@project), variant: :confirm do
        = s_('Branches|New branch')
      .js-delete-merged-branches{ data: {
          default_branch: @project.repository.root_ref,
          form_path: project_merged_branches_path(@project) }
        }
.row-content-block.gl-border-t-0
  #js-branches-sort-dropdown{ data: {
      project_branches_filtered_path: project_branches_path(@project, state: @mode),
      sort_options: branches_sort_options_hash.to_json,
      show_dropdown: @mode == 'overview' ? 'false' : 'true',
      sorted_by: @sort }
}

= render_if_exists 'projects/commits/mirror_status'

- if can_view_branch_rules?
  = render 'branch_rules_info'

.js-branch-list{ data: { diverging_counts_endpoint: diverging_commit_counts_namespace_project_branches_path(@project.namespace, @project, format: :json), default_branch: @project.default_branch } }

- if @gitaly_unavailable
  = render 'shared/errors/gitaly_unavailable', reason: s_('Branches|Unable to load branches')

- elsif @mode == 'overview' && (@active_branches.any? || @stale_branches.any?)
  = render "projects/branches/panel", branches: @active_branches, state: 'active', panel_title: s_('Branches|Active branches'), show_more_text: s_('Branches|Show more active branches'), project: @project, overview_max_branches: @overview_max_branches
  = render "projects/branches/panel", branches: @stale_branches, state: 'stale', panel_title: s_('Branches|Stale branches'), show_more_text: s_('Branches|Show more stale branches'), project: @project, overview_max_branches: @overview_max_branches

- elsif @branches.any?
  %ul.content-list.all-branches
    - @branches.each do |branch|
      = render "projects/branches/branch", branch: branch, merged: @merged_branch_names.include?(branch.name), commit_status: @branch_pipeline_statuses[branch.name], show_commit_status: @branch_pipeline_statuses.any?
  - if Feature.enabled?(:branch_list_keyset_pagination, @project)
    = render('kaminari/gitlab/without_count', previous_path: @prev_path, next_path: @next_path, event_tracking: nil)
  - else
    = paginate @branches, theme: 'gitlab'
- elsif search.present?
  = render ::Layouts::EmptyResultComponent.new(type: :search)
- else
  = render Pajamas::EmptyStateComponent.new(svg_path: 'illustrations/status/status-nothing-md.svg',
    title: s_('Branches|No branches to show'))

- if can?(current_user, :push_code, @project)
  .js-delete-branch-modal
